home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / pibasync.arc / ASYNCSEN.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-10-30  |  2.5 KB  |  48 lines

  1.          MOV     AL,[BP+<C]                 ;Pick up character to send
  2.          MOV     BX,[>Async_OBuffer_Head]   ;Get output queue head pointer
  3.          LES     DI,[>Async_OBuffer_Ptr]    ;Pick up output buffer address
  4.          ADD     DI,BX                      ;Position to current character
  5.      ES: MOV     [DI],AL                    ;Place character in output buffer
  6. ;
  7.          MOV     DX,BX                      ;Save previous head pointer
  8.          INC     BX                         ;Increment head pointer
  9.          CMP     BX,[>Async_OBuffer_Size]   ;See if past end of buffer
  10.          JLE     Send1                      ;Skip if not
  11.          XOR     BX,BX                      ;Wrap to start of buffer
  12. ;
  13. Send1:   CMP     BX,[>Async_OBuffer_Tail]   ;See if head collided with tail
  14.          JNE     Send4                      ;No -- buffer didn't fill up
  15. ;
  16.          MOV     CX,[>Async_Output_Delay]   ;Run delay loop and see if buffer drains
  17. ;
  18. Send2:   PUSH  CX                           ;Save milleseconds to go
  19.          MOV   CX,[$12]                     ;Get Turbo's delay loop value for 1 ms
  20. ;
  21. Send3:   LOOP  Send3                        ;Tight loop for 1 ms delay
  22. ;
  23.          CMP   BX,[>Async_Buffer_Tail]      ;See if buffer drained yet
  24.          JNE   Send4                        ;Yes -- OK, stop delay loop.
  25. ;
  26.          POP   CX                           ;Otherwise, get millesecond count
  27.          LOOP  Send2                        ;Decrement millesecond count and loop
  28. ;
  29.          MOV     BYTE [>Async_OBuffer_Overflow],1 ;Indicate output buffer overflow
  30.          JMP     Send5                      ;Skip updating head pointers
  31. ;
  32. Send4:   MOV     [>Async_OBuffer_Head],BX   ;Save updated head pointer
  33. ;
  34.          MOV     AX,[>Async_OBuffer_Used]   ;Get buffer use count
  35.          INC     AX                         ;Increment buffer use count
  36.          MOV     [>Async_OBuffer_Used],AX   ;Save new count
  37.          CMP     AX,[>Async_MaxOBufferUsed] ;See if larger than ever before
  38.          JLE     Send5                      ;Skip if not
  39.          MOV     [>Async_MaxOBufferUsed],AX ;Save new maximum usage
  40. ;
  41. Send5:   MOV     DX,[>Async_Uart_IER]       ;Get interrupt enable register
  42.          IN      AL,DX                      ;Check contents of IER
  43.          TEST    AL,2                       ;See if write interrupt enabled
  44.          JNZ     Send6                      ;Skip if so
  45.          OR      AL,2                       ;Else enable write interrupts ...
  46.          OUT     DX,AL                      ;... by rewriting IER contents
  47. ;
  48. Send6: